Required import statements and package install commands¶
In [ ]:
# pip install qiskit
# pip install qiskit_aer
# pip install qiskit-ibm-runtime

# Base
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from collections import Counter
import math

# Quantum
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_aer.primitives import SamplerV2 as Sampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.visualization import plot_histogram
Quantum circuit using Aer quantum simulator with 5 qubits and using Hadamard gates, running on CPU¶
In [ ]:
# create a smaller quantum circuit with 5 quantum bits (qubits)
qc = QuantumCircuit(5)

# apply Hadamard's gate to every qubit
qubits = [0, 1, 2, 3, 4]
qc.h(qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on CPU)
aer_sim = AerSimulator()

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit different amount of times, get results & compare them
sampler = Sampler()

shot_counts = [100, 1000, 10000, 100000, 1000000]
histograms = []

# run the circuit for each shot count and collect the results
for shots in shot_counts:
    result = sampler.run([qc], shots=shots).result()
    counts = result[0].data.meas.get_counts()
    histograms.append(counts)

# 1000 --> 1.000
# 1000000 --> 1.000.000
def formatLargeNumber(number):
    return format(number, ',').replace(',', '.')

# plot histograms in a vertical stack inside figure
fig, axes = plt.subplots(len(shot_counts), 1, figsize=(18, 16))
for i, counts in enumerate(histograms):
    plot_histogram(counts, ax=axes[i])
    axes[i].set_title(f'Quantum circuit ran {formatLargeNumber(shot_counts[i])} times', fontsize=17, fontweight='bold')
    axes[i].set_ylim(0, max(counts.values()) * 1.3)

plt.tight_layout(h_pad=3.0)
plt.show()
Quantum circuit using Aer quantum simulator with 29 qubits and using Hadamard gates, running on GPU¶
In [ ]:
# create quantum circuit with 29 quantum bits (qubits)
qc = QuantumCircuit(29)

# apply Hadamard's gate to every qubit
qubits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]
qc.h(qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

# print qubits and their values
for qubits, val in counts.items():
    print(f'{int(qubits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts, figsize=(25,8))
23148020: 1
290466636: 1
251450550: 1
180680355: 1
195711056: 1
7098245: 1
5563354: 1
226793403: 1
166026931: 1
254181822: 1
397303604: 1
7955078: 1
53877779: 1
325581758: 1
412823200: 1
321282184: 1
354907099: 1
104216815: 1
235730714: 1
418440626: 1
34562914: 1
522120468: 1
231674503: 1
303972703: 1
296750947: 1
314377643: 1
116042130: 1
362580209: 1
513952981: 1
325322249: 1
74118939: 1
1723120: 1
147613512: 1
514204492: 1
444829119: 1
332740992: 1
102635207: 1
499740892: 1
383316688: 1
203336525: 1
206086735: 1
240600299: 1
109174210: 1
304698474: 1
379171800: 1
183588308: 1
429527786: 1
369929187: 1
80874912: 1
121596136: 1
299906888: 1
179304599: 1
365383883: 1
257895859: 1
191573325: 1
239475187: 1
325791528: 1
155750286: 1
10565894: 1
395294792: 1
168259696: 1
336653286: 1
261134917: 1
273956073: 1
335482841: 1
269394582: 1
160801722: 1
47705881: 1
519545087: 1
381848773: 1
29756707: 1
302671599: 1
241973797: 1
517261436: 1
120285338: 1
49090799: 1
48301730: 1
147706306: 1
363249680: 1
507360180: 1
301844373: 1
264579271: 1
311236323: 1
214122926: 1
320177726: 1
208236284: 1
417549958: 1
93534764: 1
346094475: 1
57809182: 1
279325748: 1
503416330: 1
470876722: 1
469912150: 1
405459726: 1
117060498: 1
121716572: 1
413676644: 1
423992226: 1
496394425: 1
420882742: 1
261510833: 1
510618422: 1
518550467: 1
2982204: 1
108901129: 1
413001783: 1
122728381: 1
183513451: 1
171174574: 1
302508815: 1
61901814: 1
163502019: 1
128591148: 1
403148038: 1
333557545: 1
126862634: 1
452567490: 1
246767855: 1
163545220: 1
158796189: 1
126320748: 1
59568463: 1
307396533: 1
492308827: 1
381789849: 1
183218609: 1
114923719: 1
97048801: 1
258034280: 1
448119555: 1
249718910: 1
176305848: 1
360717641: 1
438757814: 1
23937123: 1
184792196: 1
247140595: 1
441525718: 1
39023563: 1
3094806: 1
145971143: 1
135000560: 1
466225284: 1
325710366: 1
100401414: 1
425257117: 1
432782405: 1
286797940: 1
249934874: 1
68190786: 1
522987371: 1
88319176: 1
482398479: 1
476683079: 1
73435084: 1
358111004: 1
327261677: 1
478168742: 1
275372640: 1
226469893: 1
60189533: 1
157534819: 1
198220224: 1
65530992: 1
373426676: 1
149047676: 1
94184696: 1
55572250: 1
40827494: 1
477924541: 1
488730384: 1
308572713: 1
525065094: 1
78167188: 1
318560087: 1
438265175: 1
470773564: 1
31565577: 1
233084461: 1
113510938: 1
3300878: 1
467013479: 1
297197422: 1
155963602: 1
425830439: 1
1060432: 1
116906326: 1
465245530: 1
361647189: 1
300888265: 1
248731254: 1
300240625: 1
427913306: 1
52555200: 1
39937809: 1
374931027: 1
353509468: 1
27864622: 1
3208360: 1
306044426: 1
99450764: 1
25387344: 1
535386633: 1
130441893: 1
78528047: 1
20950403: 1
442779166: 1
526369563: 1
316050356: 1
385882279: 1
149243750: 1
13830546: 1
245677970: 1
138351417: 1
290551971: 1
255750630: 1
139822712: 1
350167981: 1
521373509: 1
24519286: 1
324971986: 1
116751336: 1
316134074: 1
28173380: 1
262199916: 1
413771284: 1
448190956: 1
419008158: 1
505021777: 1
177055613: 1
535037359: 1
364092468: 1
355384928: 1
270351940: 1
68881144: 1
513168845: 1
424164437: 1
91667453: 1
473891827: 1
148065517: 1
343950910: 1
101710656: 1
480745045: 1
408919861: 1
67398838: 1
154599848: 1
284424671: 1
142031465: 1
213049808: 1
177737921: 1
389882878: 1
346114502: 1
396404930: 1
252983471: 1
151774082: 1
93310603: 1
516449157: 1
228672804: 1
283146714: 1
79673608: 1
460494347: 1
381226489: 1
350329967: 1
287095893: 1
86303471: 1
158130520: 1
78323500: 1
62881411: 1
40044615: 1
163694873: 1
198244393: 1
64382796: 1
292002833: 1
219149851: 1
328897189: 1
159540966: 1
281153456: 1
89048345: 1
216833805: 1
333816808: 1
373763233: 1
219581662: 1
309767471: 1
125338557: 1
28433401: 1
10082055: 1
175762021: 1
74455337: 1
480382723: 1
298369356: 1
455559683: 1
6905120: 1
57913988: 1
395181655: 1
197641112: 1
409373937: 1
298320259: 1
284810506: 1
44920231: 1
387810565: 1
52556593: 1
476764514: 1
156947639: 1
103950274: 1
416390405: 1
104173500: 1
355628155: 1
136650766: 1
372093640: 1
333589718: 1
14538298: 1
339977398: 1
88750138: 1
398720737: 1
95196644: 1
374385091: 1
237848052: 1
61659304: 1
321036968: 1
339446596: 1
279338183: 1
415692372: 1
298780136: 1
105754274: 1
57493566: 1
104632821: 1
336702097: 1
480729832: 1
146527864: 1
268919925: 1
421887904: 1
167379676: 1
522315296: 1
300879487: 1
58320049: 1
119930653: 1
289105551: 1
205566888: 1
358031805: 1
250955013: 1
213111929: 1
8170336: 1
8876498: 1
18107250: 1
521805419: 1
467199934: 1
161884975: 1
234905563: 1
118787634: 1
298201263: 1
31835450: 1
317354280: 1
220184975: 1
200685497: 1
521211620: 1
236923651: 1
254592564: 1
80787262: 1
338782055: 1
192212067: 1
178297582: 1
280877168: 1
58144135: 1
470795076: 1
122813315: 1
488042583: 1
358287790: 1
136812485: 1
169728432: 1
453494278: 1
515008487: 1
299453329: 1
108024220: 1
184198550: 1
387941722: 1
283336125: 1
161503560: 1
233226506: 1
130207528: 1
455392141: 1
180769796: 1
87274860: 1
221706144: 1
273058915: 1
48963716: 1
300587653: 1
108778320: 1
136890665: 1
506963949: 1
255270127: 1
284349261: 1
390486965: 1
498949879: 1
199596797: 1
432679818: 1
166778280: 1
233441111: 1
19540677: 1
67507395: 1
325373027: 1
364252525: 1
405379067: 1
511921842: 1
451584448: 1
97048995: 1
246950489: 1
200587381: 1
349335522: 1
219624779: 1
177842613: 1
365225162: 1
283908013: 1
166292815: 1
60536539: 1
464098532: 1
319461309: 1
280757402: 1
177250932: 1
364683598: 1
310091553: 1
466148023: 1
237139692: 1
127218842: 1
248130028: 1
143014246: 1
424858550: 1
17479416: 1
78750996: 1
29139480: 1
55386132: 1
26687089: 1
55623386: 1
34517327: 1
439150245: 1
272642796: 1
435797646: 1
314091995: 1
462104014: 1
125048691: 1
435072565: 1
424872334: 1
123655614: 1
362114834: 1
102767593: 1
457916604: 1
465354645: 1
66989823: 1
290852090: 1
509959680: 1
218662597: 1
169388407: 1
404879856: 1
245364006: 1
330815329: 1
426829775: 1
369983865: 1
309489547: 1
267938331: 1
495286093: 1
215438868: 1
33922860: 1
221335698: 1
92427887: 1
436070598: 1
65328058: 1
48714918: 1
260430466: 1
6890907: 1
436110270: 1
369091252: 1
281231776: 1
74118915: 1
171998837: 1
445471341: 1
117665177: 1
32238414: 1
361748055: 1
58380182: 1
3007072: 1
343735446: 1
205826546: 1
375438288: 1
313558553: 1
522812130: 1
451474544: 1
147070643: 1
133178033: 1
269213605: 1
372790094: 1
528649812: 1
93715521: 1
278035885: 1
360320907: 1
375638482: 1
107380120: 1
258888319: 1
152233691: 1
14801269: 1
411250728: 1
227752295: 1
46470682: 1
146677693: 1
64217684: 1
226231778: 1
321213787: 1
401661210: 1
452165804: 1
407546200: 1
434428785: 1
76778371: 1
65079289: 1
21139635: 1
413587201: 1
46889964: 1
58755710: 1
452732514: 1
348498420: 1
196634792: 1
281411384: 1
300363381: 1
101142975: 1
449221502: 1
128027405: 1
415840942: 1
240098337: 1
383398137: 1
200027955: 1
374341216: 1
306932235: 1
194113973: 1
472464484: 1
139469269: 1
495565461: 1
47186820: 1
345726017: 1
421099730: 1
212371380: 1
135644700: 1
69415329: 1
387471989: 1
468116854: 1
400345611: 1
19380102: 1
152887191: 1
443026781: 1
463005872: 1
449330558: 1
127217851: 1
514737192: 1
381024158: 1
19301821: 1
392323485: 1
272899161: 1
374352256: 1
296130968: 1
308758167: 1
17449033: 1
176361714: 1
400680448: 1
92583088: 1
296604199: 1
434438632: 1
252589030: 1
517461700: 1
113844965: 1
467539706: 1
198161873: 1
481865493: 1
101686562: 1
147414374: 1
441399474: 1
249064815: 1
229091772: 1
18075788: 1
34591659: 1
222515750: 1
253610494: 1
194331185: 1
53337981: 1
535611330: 1
174117195: 1
274501566: 1
287594574: 1
54463746: 1
299858381: 1
325189975: 1
245728080: 1
382416809: 1
382923089: 1
6716947: 1
6786152: 1
238631680: 1
88877922: 1
472409555: 1
340330864: 1
535932868: 1
286023558: 1
276640497: 1
533573077: 1
471603913: 1
35209248: 1
405315500: 1
258780383: 1
192332119: 1
82487765: 1
387952190: 1
315507538: 1
327804708: 1
326534399: 1
479380832: 1
433323866: 1
423194063: 1
480991916: 1
258573404: 1
264460084: 1
184263413: 1
162193709: 1
439824036: 1
239503274: 1
203997736: 1
165558684: 1
238160905: 1
286883016: 1
6136814: 1
314668684: 1
433884599: 1
236422001: 1
98779281: 1
395599388: 1
189520518: 1
519169918: 1
502209856: 1
29203273: 1
118821625: 1
523477430: 1
96754899: 1
215305902: 1
401406310: 1
482210123: 1
476148040: 1
258635904: 1
511544535: 1
23487296: 1
315323483: 1
201091078: 1
517703371: 1
266577765: 1
495259896: 1
150080707: 1
243811195: 1
394860431: 1
40314209: 1
286225144: 1
236693750: 1
40229745: 1
208843296: 1
346689440: 1
498022236: 1
107167749: 1
164659951: 1
253719248: 1
346848473: 1
115753980: 1
131323948: 1
21152928: 1
67591452: 1
129190338: 1
161057426: 1
76185973: 1
96176364: 1
184744552: 1
211319896: 1
184180218: 1
108029817: 1
432838989: 1
321545861: 1
354948540: 1
408064297: 1
510684550: 1
407159656: 1
18465744: 1
193017606: 1
453635349: 1
409758365: 1
63307299: 1
533922817: 1
267302152: 1
291824902: 1
461442212: 1
385882169: 1
473296364: 1
446133866: 1
221561783: 1
6574769: 1
289062532: 1
433807712: 1
251519537: 1
196689885: 1
19867572: 1
138648581: 1
406467214: 1
288647978: 1
9351741: 1
29915784: 1
206692699: 1
131389487: 1
226667024: 1
507159290: 1
268967850: 1
443180586: 1
191008943: 1
262355895: 1
532961054: 1
410619745: 1
84902124: 1
129804007: 1
56694985: 1
68907481: 1
228697457: 1
225896104: 1
294217471: 1
495888758: 1
270147397: 1
473180107: 1
322194714: 1
293651105: 1
522450219: 1
7377122: 1
326557564: 1
435494513: 1
371611602: 1
96905874: 1
494397898: 1
119989532: 1
324640424: 1
25336877: 1
466787221: 1
157077032: 1
193868075: 1
71083856: 1
187671524: 1
335796922: 1
201691198: 1
181665542: 1
2457039: 1
318717411: 1
423718103: 1
263404525: 1
403906145: 1
535590558: 1
496856613: 1
213417226: 1
23898298: 1
11221108: 1
74027645: 1
78671325: 1
530422694: 1
373689329: 1
41999704: 1
271263319: 1
158405008: 1
291798997: 1
187454993: 1
387445610: 1
124714414: 1
43410902: 1
151562762: 1
121353843: 1
511486916: 1
4321551: 1
458693008: 1
292032926: 1
145464143: 1
21597193: 1
216875543: 1
452479117: 1
515748312: 1
236796253: 1
373002605: 1
454489471: 1
209608694: 1
401639101: 1
313425533: 1
503944710: 1
248257397: 1
362185600: 1
37077909: 1
249144288: 1
363192464: 1
176217603: 1
419873277: 1
322698201: 1
127121328: 1
305268041: 1
306691261: 1
90869036: 1
109750116: 1
367301140: 1
412658148: 1
284366524: 1
243996190: 1
160141202: 1
290756280: 1
328564872: 1
198973136: 1
378252071: 1
420177873: 1
331190101: 1
154341440: 1
341263472: 1
176468369: 1
222992567: 1
505117003: 1
481717211: 1
103447316: 1
260385024: 1
119659364: 1
380277116: 1
197094319: 1
86575694: 1
115040063: 1
39337062: 1
59914452: 1
24987745: 1
428743339: 1
316782761: 1
220432247: 1
217694260: 1
312633228: 1
385039608: 1
500684144: 1
37543037: 1
337425721: 1
136126745: 1
45509101: 1
114181812: 1
268647817: 1
295665943: 1
257524997: 1
116571390: 1
436837855: 1
26043911: 1
451643448: 1
493965996: 1
395570552: 1
343298856: 1
162507486: 1
147325468: 1
324163685: 1
344357869: 1
181287807: 1
285878960: 1
164851017: 1
67527199: 1
101146448: 1
3687976: 1
435656557: 1
201476775: 1
203812879: 1
252840939: 1
429943310: 1
216497479: 1
294838978: 1
415127717: 1
103886963: 1
166750180: 1
370614519: 1
101885202: 1
220125854: 1
271918086: 1
131667618: 1
170974581: 1
416918070: 1
450279947: 1
148966683: 1
440320900: 1
42764870: 1
478826955: 1
298749779: 1
482944413: 1
27866690: 1
122484812: 1
374825824: 1
354614796: 1
267079816: 1
73225338: 1
357163567: 1
351906770: 1
258582030: 1
428536252: 1
512442707: 1
299856641: 1
270212632: 1
516523264: 1
372988432: 1
180538044: 1
405780122: 1
28857767: 1
463554924: 1
496862625: 1
25804819: 1
209990362: 1
56791568: 1
182788020: 1
138516650: 1
245414953: 1
222608095: 1
284258441: 1
366464997: 1
521538096: 1
329012473: 1
138485738: 1
428993545: 1
247331195: 1
463889346: 1
300248626: 1
271439278: 1
252680074: 1
419490830: 1
72764131: 1
177707458: 1
51979309: 1
130962826: 1
211192595: 1
174782343: 1
317266207: 1
125351789: 1
306639328: 1
319350632: 1
76004505: 1
485231965: 1
270062715: 1
345606728: 1
141368328: 1
476522922: 1
493187818: 1
183813258: 1
389356425: 1
371127484: 1
311623934: 1
150785490: 1
90222865: 1
195059265: 1
300141040: 1
298275405: 1
38440706: 1
371363556: 1
409244150: 1
274586337: 1
296492117: 1
380122741: 1
291692337: 1
442436761: 1
427551520: 1
324346214: 1
181498189: 1
345938009: 1
296406621: 1
282975605: 1
489476184: 1
497763186: 1
505423381: 1
93161654: 1
436801185: 1
481855353: 1
86975085: 1
416095647: 1
243995022: 1
92711237: 1
469486880: 1
382836383: 1
258124271: 1
320365805: 1
241955195: 1
461141604: 1
133416965: 1
25043513: 1
32166906: 1
153312542: 1
306505604: 1
3385610: 1
389430089: 1
48812194: 1
233072600: 1
485542191: 1
521793826: 1
536313251: 1
96385080: 1
531929932: 1
370244470: 1
521231772: 1
43201644: 1
148913612: 1
57786850: 1
349684571: 1
29453999: 1
289992404: 1
521112388: 1
389277030: 1
Out[ ]:
Quantum circuit using Aer quantum simulator with 29 qubits and using Rotation gates, running on GPU¶

Calculations of angles for the following probabilities: 0.25, 0.5 and 0.75


$p = 0.25$

$\sqrt{p} = \sqrt{0.25} = 0.5$

$theta = 2 * arcsin(0.5) = pi/3 = 60°$


$p = 0.5$

$\sqrt{p} = \sqrt{0.5} = 0.707$

$theta = 2 * arcsin(0.707) = pi/2 = 90°$


$p = 0.75$

$\sqrt{p} = \sqrt{0.75} = 0.866$

$theta = 2 * arcsin(0.866) = 2pi/3 = 120°$

In [ ]:
# create quantum circuit with 29 qubits
qc = QuantumCircuit(29)

qubits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]

# define probabilities
probabilities = [0.25, 0.5, 0.75]

# calculate rotation angles in radians and convert to degrees
angles_rad = [round(2 * math.asin(math.sqrt(p)), 2) for p in probabilities]
angles_deg = [round(math.degrees(angle)) for angle in angles_rad]

print(f'angles in radians: {angles_rad}')
print(f'angles in degrees: {angles_deg}')

# pi/3 (60°) = 25 %
# pi/2 (90°) = 50 %
# 2*pi/3 (120°) = 75 %

# rotation gates set to pi/2 (50%) probability for each qubit
qc.rx(math.pi/2, qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
angles in radians: [1.05, 1.57, 2.09]
angles in degrees: [60, 90, 120]
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

# print qubits and their values
for qubits, val in counts.items():
    print(f'{int(qubits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts, figsize=(25,8))
215091707: 1
13523204: 1
307293192: 1
147487978: 1
316431848: 1
90695948: 1
400392148: 1
73643310: 1
217834257: 1
329871086: 1
192321813: 1
251904698: 1
490316122: 1
328458696: 1
389977047: 1
430421560: 1
254621057: 1
151157280: 1
270665728: 1
242557501: 1
194745805: 1
227712904: 1
367193863: 1
48387482: 1
312990927: 1
501692606: 1
220537357: 1
192080890: 1
144718595: 1
416073073: 1
515201528: 1
210501491: 1
234596200: 1
487185019: 1
172024489: 1
291091856: 1
87604182: 1
272692688: 1
202620590: 1
380424032: 1
252562212: 1
281731302: 1
182793753: 1
310129343: 1
77760698: 1
398890110: 1
513056408: 1
220898797: 1
125695012: 1
520936225: 1
305481342: 1
4700718: 1
124264763: 1
343480211: 1
243516233: 1
235185242: 1
228000405: 1
367388300: 1
60175245: 1
436850045: 1
20018381: 1
389028390: 1
279708355: 1
476271944: 1
450754550: 1
66253367: 1
77518074: 1
266861287: 1
266282221: 1
511139610: 1
327338249: 1
371711095: 1
86619377: 1
89739827: 1
143526854: 1
313358320: 1
278356447: 1
72267713: 1
129460505: 1
390090740: 1
9706669: 1
305681768: 1
382465829: 1
443882311: 1
196990721: 1
212550150: 1
417283143: 1
409361105: 1
109873917: 1
206086660: 1
131857755: 1
172918964: 1
166288249: 1
2954643: 1
528872465: 1
41427547: 1
298293705: 1
148839919: 1
354990307: 1
379088104: 1
478158648: 1
231237971: 1
392664531: 1
28232086: 1
213561095: 1
106149093: 1
185678210: 1
530033086: 1
179135642: 1
351054643: 1
176233720: 1
290340004: 1
222201792: 1
136144366: 1
175443335: 1
99220725: 1
294768506: 1
324235219: 1
453422669: 1
206033940: 1
132715015: 1
179274643: 1
284754533: 1
294226205: 1
482445960: 1
291899342: 1
145992914: 1
102357477: 1
10002900: 1
489439004: 1
365944914: 1
115185900: 1
505512302: 1
294039034: 1
105687991: 1
302367157: 1
7592486: 1
424271161: 1
204133054: 1
65470080: 1
391269109: 1
324599363: 1
188865161: 1
192849309: 1
108399754: 1
444763119: 1
242703728: 1
501069149: 1
460809361: 1
45829120: 1
493749141: 1
211149433: 1
55018337: 1
277955570: 1
389263746: 1
486208368: 1
170350444: 1
486631627: 1
416450199: 1
425450630: 1
312315767: 1
535215833: 1
15431784: 1
354400285: 1
414547137: 1
404937: 1
5592685: 1
228843248: 1
259699484: 1
228999512: 1
382031384: 1
481095898: 1
320635913: 1
124196253: 1
418196063: 1
266150481: 1
503647830: 1
419161028: 1
37697105: 1
495101026: 1
110723229: 1
316477124: 1
305561232: 1
492856454: 1
506075326: 1
264208582: 1
507629910: 1
321130974: 1
236409551: 1
442304501: 1
28251338: 1
436220859: 1
263407039: 1
314767362: 1
411860452: 1
159778042: 1
247721804: 1
488826637: 1
306613383: 1
252528780: 1
70180075: 1
265959130: 1
322030340: 1
483654258: 1
507066578: 1
279592555: 1
316091334: 1
388291074: 1
182456894: 1
373687749: 1
395253166: 1
471965497: 1
61364398: 1
453214468: 1
38466511: 1
309442997: 1
379100336: 1
321771295: 1
178272787: 1
88345416: 1
2606468: 1
469402622: 1
370557378: 1
40203806: 1
161520485: 1
475010723: 1
516228026: 1
444346622: 1
307670078: 1
124503854: 1
224749404: 1
325633541: 1
63025542: 1
444772216: 1
164605004: 1
258000864: 1
126981284: 1
419245216: 1
139783603: 1
280522378: 1
310199686: 1
278289436: 1
237412649: 1
302130646: 1
96467172: 1
478988666: 1
300736835: 1
493944170: 1
437351237: 1
74914926: 1
413166671: 1
515597623: 1
381459784: 1
410679080: 1
102364779: 1
91516277: 1
272488876: 1
103415059: 1
199766096: 1
448342228: 1
284955402: 1
255017372: 1
137783795: 1
408860096: 1
294990680: 1
170562024: 1
482667363: 1
71554870: 1
526470891: 1
143111360: 1
360601451: 1
243643912: 1
525300963: 1
50247621: 1
438630173: 1
167128922: 1
464987501: 1
124565567: 1
423460707: 1
334109338: 1
342921005: 1
404891491: 1
113822214: 1
328848563: 1
12178524: 1
498331079: 1
98072429: 1
503688009: 1
216141637: 1
218845334: 1
203032819: 1
154305916: 1
282206359: 1
120324712: 1
67130424: 1
427585605: 1
444529410: 1
149968963: 1
31507720: 1
243936516: 1
125724904: 1
514364588: 1
4952581: 1
94880014: 1
440548973: 1
115614946: 1
214938044: 1
450224359: 1
235230805: 1
93538394: 1
342867168: 1
455720334: 1
121301916: 1
527325043: 1
500621745: 1
467381191: 1
359377693: 1
481025312: 1
500022085: 1
251805570: 1
354243437: 1
189438551: 1
436699288: 1
49763473: 1
418949499: 1
249920025: 1
5193487: 1
118572130: 1
205772658: 1
159069519: 1
181355891: 1
182221328: 1
228156231: 1
301809764: 1
329126794: 1
129051010: 1
340854283: 1
46456503: 1
116730087: 1
237202102: 1
334444282: 1
210687414: 1
483404682: 1
157884462: 1
438877747: 1
348653943: 1
384458529: 1
394943061: 1
117511378: 1
2881987: 1
84838505: 1
509311921: 1
345001784: 1
148129602: 1
511758664: 1
53722126: 1
322306344: 1
462082256: 1
246291007: 1
297670270: 1
146771290: 1
245869282: 1
217927593: 1
60518301: 1
431162500: 1
533814832: 1
132611522: 1
205422004: 1
171070465: 1
536652688: 1
131860990: 1
290125906: 1
38737883: 1
54925633: 1
332844183: 1
445023706: 1
101743580: 1
446106581: 1
439476271: 1
54363459: 1
438921272: 1
336132282: 1
368454084: 1
76994326: 1
354887032: 1
477724715: 1
507023092: 1
244191306: 1
366628669: 1
47721418: 1
343012893: 1
386954325: 1
86061418: 1
305583927: 1
180215568: 1
181814311: 1
181369871: 1
193335980: 1
376043809: 1
142236389: 1
418037618: 1
357244661: 1
150752398: 1
117892831: 1
368020212: 1
321832890: 1
411931508: 1
190359029: 1
76335554: 1
222535782: 1
370307734: 1
359968834: 1
171732162: 1
183273410: 1
98139484: 1
352221630: 1
137352636: 1
534774362: 1
298770395: 1
393357366: 1
229724723: 1
302855378: 1
402246126: 1
228715113: 1
246244057: 1
359574631: 1
323059418: 1
287792985: 1
364614286: 1
1055694: 1
353514485: 1
74756774: 1
57259671: 1
382480426: 1
233550995: 1
85100620: 1
66772456: 1
829951: 1
111734374: 1
19515343: 1
180054661: 1
479529036: 1
193031497: 1
527820169: 1
352508184: 1
513270950: 1
193070269: 1
257306292: 1
187841055: 1
38244747: 1
533604136: 1
409921558: 1
301786862: 1
261898280: 1
322975790: 1
277459323: 1
467823594: 1
479265955: 1
157888345: 1
191342739: 1
23622663: 1
482629770: 1
251784709: 1
451515922: 1
374741492: 1
137083145: 1
64871045: 1
201224829: 1
340095906: 1
258032543: 1
111162558: 1
330840884: 1
132748890: 1
425542729: 1
492474538: 1
197621975: 1
255827729: 1
42432557: 1
144445514: 1
196268484: 1
315094221: 1
504644539: 1
393907396: 1
511661744: 1
451453933: 1
373913149: 1
209968667: 1
391796994: 1
282918634: 1
372636702: 1
150863431: 1
118833346: 1
488082240: 1
337439745: 1
486674029: 1
51888293: 1
477367266: 1
463728311: 1
246209487: 1
308444032: 1
309955882: 1
532251221: 1
135237557: 1
264726240: 1
310446709: 1
420573306: 1
215271903: 1
69973477: 1
9285337: 1
367737535: 1
516419806: 1
321974210: 1
335359965: 1
165054684: 1
263357485: 1
121114517: 1
60669051: 1
186400498: 1
406535931: 1
55932924: 1
205055671: 1
53091349: 1
257755591: 1
419738541: 1
424096940: 1
319004225: 1
132325977: 1
34118067: 1
24049920: 1
224412327: 1
322308888: 1
450960837: 1
454168926: 1
365172139: 1
282023693: 1
223235228: 1
372792327: 1
154724182: 1
222873036: 1
39114275: 1
43050270: 1
280502741: 1
287840164: 1
61770742: 1
445036301: 1
485553365: 1
341024009: 1
412828479: 1
367817092: 1
311073703: 1
488097851: 1
37475638: 1
230373700: 1
29702919: 1
232280393: 1
172803912: 1
106909429: 1
9237975: 1
413286627: 1
324147461: 1
320336127: 1
269630298: 1
186587336: 1
56376449: 1
439943192: 1
146781419: 1
484136167: 1
340434162: 1
272249346: 1
264216295: 1
262834952: 1
525199430: 1
344051101: 1
55140765: 1
56806061: 1
28642299: 1
139079247: 1
302343646: 1
391577270: 1
226537156: 1
457610879: 1
226929797: 1
104252657: 1
494971880: 1
366586115: 1
46003405: 1
77656294: 1
65170635: 1
488858117: 1
288279580: 1
534857411: 1
170810996: 1
228453921: 1
198600477: 1
178128897: 1
228603366: 1
33290101: 1
355493612: 1
338017622: 1
79572039: 1
387688949: 1
97266442: 1
307771523: 1
436822306: 1
497287399: 1
220330246: 1
204376173: 1
27118681: 1
491113519: 1
2034193: 1
505011796: 1
349209555: 1
484559382: 1
386137874: 1
474658210: 1
5522282: 1
410756224: 1
409190387: 1
310133636: 1
165337250: 1
376001198: 1
174473152: 1
428436670: 1
366939657: 1
51170536: 1
397403434: 1
71652064: 1
162906074: 1
341223502: 1
384444061: 1
264167384: 1
12985401: 1
485305138: 1
29397041: 1
275705585: 1
440110265: 1
15095639: 1
372464141: 1
129788115: 1
438125851: 1
219897310: 1
60855120: 1
346845324: 1
327291073: 1
284637293: 1
18544736: 1
73587083: 1
111203711: 1
265790137: 1
349300522: 1
49400183: 1
513512820: 1
89375683: 1
90584201: 1
97433081: 1
144685575: 1
117612859: 1
28596730: 1
120073482: 1
376400388: 1
126779511: 1
31040378: 1
393477263: 1
268452828: 1
289763353: 1
187088449: 1
26028473: 1
340252343: 1
252007523: 1
533554969: 1
402420377: 1
464843391: 1
414143287: 1
200835811: 1
376077526: 1
160383127: 1
516279375: 1
399819944: 1
479520695: 1
355123498: 1
406821720: 1
213965557: 1
101281832: 1
149205869: 1
318904680: 1
269321094: 1
382312243: 1
206540661: 1
135518901: 1
155740564: 1
2250522: 1
234121838: 1
211164875: 1
504354707: 1
259894415: 1
152870417: 1
80460877: 1
489081479: 1
437535389: 1
233434263: 1
120795635: 1
93704091: 1
57788530: 1
384634792: 1
346539934: 1
3062085: 1
535600085: 1
214742324: 1
37710246: 1
202872980: 1
446637112: 1
96811305: 1
194263704: 1
2163813: 1
217478144: 1
183074454: 1
88816499: 1
22296208: 1
531795800: 1
510705240: 1
388320280: 1
466353077: 1
299920781: 1
225559481: 1
510026993: 1
245177005: 1
32085701: 1
181764995: 1
456358461: 1
293264292: 1
15733901: 1
203195260: 1
512496801: 1
165223927: 1
374683044: 1
103996155: 1
484919109: 1
341106496: 1
448742408: 1
281340068: 1
304008926: 1
179261151: 1
98763778: 1
55186787: 1
404813801: 1
300692413: 1
170082958: 1
366980380: 1
239837746: 1
100069189: 1
284127323: 1
331483856: 1
451313234: 1
529979654: 1
85135726: 1
22332967: 1
413280506: 1
442833034: 1
300494777: 1
142647069: 1
78284101: 1
430038732: 1
534043269: 1
53784875: 1
322001541: 1
227140815: 1
289953828: 1
90552491: 1
377128743: 1
348680522: 1
238338747: 1
6683732: 1
524762984: 1
523253560: 1
398869731: 1
323471133: 1
505154824: 1
342716650: 1
273450173: 1
435218766: 1
394732345: 1
380823023: 1
141093354: 1
421101253: 1
489998662: 1
375424132: 1
199713411: 1
214974249: 1
309765445: 1
377824087: 1
434669270: 1
205212881: 1
161422318: 1
262477421: 1
171575528: 1
92920634: 1
464685239: 1
163612438: 1
533742041: 1
283017126: 1
276391132: 1
501252241: 1
186115671: 1
507139920: 1
84945471: 1
272787168: 1
221748039: 1
26018590: 1
498611190: 1
305813214: 1
481594796: 1
191844517: 1
407317461: 1
5888203: 1
525404841: 1
286121970: 1
398125005: 1
18425854: 1
70717069: 1
291416229: 1
240011235: 1
89819465: 1
94770727: 1
487367324: 1
125592289: 1
339380978: 1
305420364: 1
409523911: 1
360418911: 1
82333422: 1
74842761: 1
106011339: 1
335473766: 1
127803060: 1
272131559: 1
456339285: 1
256090345: 1
267011363: 1
211131962: 1
247783885: 1
341938767: 1
471412573: 1
452106054: 1
238396431: 1
433079920: 1
316355912: 1
424010356: 1
409832591: 1
156397653: 1
71273492: 1
74530129: 1
14500504: 1
156013319: 1
143597496: 1
477826505: 1
168674583: 1
529613191: 1
58632995: 1
498526827: 1
520829710: 1
205499276: 1
364814056: 1
254804582: 1
8689321: 1
189693484: 1
509081302: 1
114611214: 1
467754506: 1
121804847: 1
413763867: 1
513207896: 1
316915600: 1
157271597: 1
240910747: 1
218386880: 1
15598259: 1
143505349: 1
326390670: 1
341868744: 1
18482319: 1
278882605: 1
27131297: 1
497378277: 1
403077514: 1
491511098: 1
456443021: 1
42171054: 1
215237679: 1
229320881: 1
195662365: 1
238870314: 1
426895165: 1
390404416: 1
370933610: 1
40557562: 1
395102560: 1
205038439: 1
453870117: 1
145259625: 1
27771555: 1
452037066: 1
334215831: 1
335135801: 1
6986670: 1
327217876: 1
314250330: 1
292206404: 1
317864998: 1
232091124: 1
149688178: 1
282551238: 1
267906495: 1
506929180: 1
411731587: 1
256167611: 1
527391620: 1
314564968: 1
393845523: 1
495246181: 1
390134029: 1
478342869: 1
490448796: 1
453415407: 1
209421853: 1
97436911: 1
288199620: 1
175911367: 1
401084820: 1
450697910: 1
191850658: 1
170887843: 1
39403203: 1
225788337: 1
298935753: 1
452107819: 1
216389661: 1
148768892: 1
112627578: 1
95497066: 1
86556781: 1
329323937: 1
478499505: 1
515445995: 1
372370074: 1
447837257: 1
294126805: 1
179214724: 1
132643428: 1
210242474: 1
15391865: 1
147335574: 1
275898318: 1
24354770: 1
138480624: 1
277314183: 1
228128683: 1
391264868: 1
160388645: 1
413009543: 1
306584229: 1
500041428: 1
470028645: 1
38656112: 1
147819461: 1
358779548: 1
178800724: 1
94875660: 1
247964126: 1
69577565: 1
281418181: 1
181705211: 1
1380784: 1
128389334: 1
18069951: 1
14282277: 1
326292058: 1
165678981: 1
361452083: 1
215025473: 1
125221673: 1
454146852: 1
487824374: 1
160677988: 1
202528956: 1
531230601: 1
532894545: 1
39528321: 1
232478269: 1
337770093: 1
311567461: 1
219196747: 1
433526665: 1
393385437: 1
296723445: 1
187771713: 1
33696618: 1
327253381: 1
111842554: 1
263327098: 1
256880910: 1
Out[ ]:

Calculation of angle (in radians) for generating number 3 with a 50 % probability¶

3(10) = 11(2)

$P(11) = p * p = p^2$

$p^2 = 0.5$

$p = \sqrt{0.5} = 1/\sqrt{2} = 0.707$

$p = sin^2(\theta/2)$

$sin^2(\theta/2) = 1/\sqrt(2)$

$sin(\theta/2) = \sqrt{1/\sqrt{2}} = 0.841$

$\theta/2 = arcsin(0.841) = 57° = 1.0$ radian

$\theta = 2 * 57 = 114.5° = 2.0$ radian

In [ ]:
# create quantum circuit with 2 qubits (number 3 in decimal only requires 2 binary digits)
qc = QuantumCircuit(2)

qubits = [0, 1]
theta = 2

# rotation gates set to 2 radians probability for each of the 2 qubits
qc.rx(theta, qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=100).result()

counts = result[0].data.meas.get_counts()

for bits, val in counts.items():
    print(f'{int(bits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts)
0: 11
3: 46
1: 22
2: 21
Out[ ]:

Calculation of angle (in radians) for generating 576(10) = 1001000000(2) with a 25 % probability¶

Since only 2 bits in the binary representation of the decimal number 576 are set to 1, we can do the following:

$P = 0.25$

$P = p^2$ (power of 2 because only 2 bits are set to 1)

$p^2 = 0.25$

$p = \sqrt{0.25} = 0.5$

$p = sin^2(\theta/2)$

$sin^2(\theta/2) = 0.5$

$sin(\theta/2) = \sqrt{0.5} = 0.707$

$\theta/2 = arcsin(0.707) = 45° = 0.785$ radian

$\theta = 2 * 45 = 90° = 1.57$ radian

In [ ]:
# create quantum circuit with 10 qubits (number 576 in decimal requires 10 binary digits)
qc = QuantumCircuit(10)

# 576 --> 1001000000
# only 6th and 9th bit are set to 1 (if counting from the back to the front)
qubits = [6, 9] 
# calculated theta in radians
theta = 1.57

# rotation gates set to 2 radians probability for each of the 2 qubits
qc.rx(theta, qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

for bits, val in counts.items():
    print(f'{int(bits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts)
512: 245
0: 228
576: 289
64: 238
Out[ ]:

Calculation of angle (in radians) for generating 576(10) = 1001000000(2) with a 50 % probability¶

Since only 2 bits in the binary representation of the decimal number 576 are set to 1, we can do the following:

$P = 0.5$

$P = p^2$ (power of 2 because only 2 bits are set to 1)

$p^2 = 0.5$

$p = \sqrt{0.5} = 0.707$

$p = sin^2(\theta/2)$

$sin^2(\theta/2) = 0.707$

$sin(\theta/2) = \sqrt{0.707} = 0.841$

$\theta/2 = arcsin(0.841) = 57° = 1.0$ radian

$\theta = 2 * 57 = 114.5° = 2.0$ radian

In [ ]:
# create quantum circuit with 10 qubits (number 576 in decimal requires 10 binary digits)
qc = QuantumCircuit(10)

# 576 --> 1001000000
# only 6th and 9th bit are set to 1 (if counting from the back to the front)
qubits = [6, 9]
# calculated theta in radians
theta = 2

# rotation gates set to 2 radians probability for each of the 2 qubits
qc.rx(theta, qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

for bits, val in counts.items():
    print(f'{int(bits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts)
64: 206
576: 498
512: 199
0: 97
Out[ ]:

Calculation of angle (in radians) for generating 576(10) = 1001000000(2) with a 75 % probability¶

Since only 2 bits in the binary representation of the decimal number 576 are set to 1, we can do the following:

$P = 0.75$

$P = p^2$ (power of 2 because only 2 bits are set to 1)

$p^2 = 0.75$

$p = \sqrt{0.75} = 0.866$

$p = sin^2(\theta/2)$

$sin^2(\theta/2) = 0.866$

$sin(\theta/2) = \sqrt{0.866} = 0.931$

$\theta/2 = arcsin(0.931) = 68.6° = 1.2$ radian

$\theta = 2 * 68.6 = 137.2° = 2.4$ radian

In [ ]:
# create quantum circuit with 10 qubits (number 576 in decimal requires 10 binary digits)
qc = QuantumCircuit(10)

# 576 --> 1001000000
# only 6th and 9th bit are set to 1 (if counting from the back to the front)
qubits = [6, 9]
# calculated theta in radians
theta = 2.4

# rotation gates set to 2 radians probability for each of the 2 qubits
qc.rx(theta, qubits)

# measure all qubits
qc.measure_all()

# use local quantum simulator (running on GPU)
aer_sim = AerSimulator(device='GPU')

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=aer_sim, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

for bits, val in counts.items():
    print(f'{int(bits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts)
64: 108
576: 751
512: 119
0: 22
Out[ ]:

Kaj ste morali spremeniti v algoritmu, da ste dosegli poljubno verjetnost generiranja naključnih števil?¶

Z uporabo enačb sem moral za poljubno verjetnost izračunati kot theta (v radianih).


Ali bi lahko zgoraj navedene poljubne verjetnosti (0,25, 0,50 in 0,75), dosegli s pomočjo Hadamardovih vrat? Odgovor utemeljite.¶

Z uporabo Hadamardovih vrat smo pri generaciji s poljubnimi verjetnostmi omejeni, in sicer lahko s Hadamardovimi vrati generiramo samo s 50-odstotno verjetnostjo. Razlog za to je narava njihovega delovanja, saj Hadamardova vrata generirajo samo ekvivalentno superpozicijo qubitov $|0\rangle$ in $|1\rangle$.


S kakšno verjetnostjo se v vašem generatorju generirajo ostala števila (poleg tistega, ki ga določajo zadnje tri cifre vaše vpisne številke)?¶

Števila, ki imajo v binarni obliki na enakih mestih (kot število 576) bite nastavljene na 1, so generirana z večjo verjetnostjo, kot tista, ki se s številom 576 v bitih ne ujemajo.


Large quantum circuit using IBM's quantum simulator with 127 qubits¶
In [ ]:
# create a larger quantum circuit with 127 quantum bits (qubits)
qc = QuantumCircuit(127)

# apply Hadamard's gate to every qubit
qubits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
          33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
          65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
          97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126]

qc.h(qubits)

# measure all qubits
qc.measure_all()

# use IBM's quantum computer simulator (register here to get API TOKEN: https://quantum.ibm.com/)
API_TOKEN = "1ac02f42d976d14a0cea984659aa1d1d13bbf4746537030ad3ee4912f7ac00f4d3fa678570de8ce909d2b30ed887892f03e92f05c306ac94229dce2dbfe2f830"
provider = QiskitRuntimeService(channel='ibm_quantum', token=API_TOKEN)
backend = provider.backend("ibm_kyoto")

# genertate ISA instruction set architecture
pm = generate_preset_pass_manager(backend=backend, optimization_level=0)
qc_isa = pm.run(qc)

# visualize quantum circuit
qc_isa.draw('mpl')
Out[ ]:
In [ ]:
# run quantum circuit 1000 times & get results
sampler = Sampler()
result = sampler.run([qc_isa], shots=1000).result()

counts = result[0].data.meas.get_counts()

# print qubits and their values
for qubits, val in counts.items():
    print(f'{int(qubits, 2)}: {val}')

# plot histogram of results
plot_histogram(counts, figsize=(30,8))
241100667: 1
203271275: 1
143524757: 1
311294982: 1
397062628: 1
107633279: 1
482472602: 1
530759543: 1
265098758: 1
314539897: 1
409705794: 1
123137409: 1
449308354: 1
120510936: 1
244411909: 1
435169315: 1
426991800: 1
276324843: 1
344800856: 1
17522445: 1
160647841: 1
351325243: 1
80001157: 1
323631565: 1
350995043: 1
95768813: 1
56204285: 1
372137644: 1
336698898: 1
117907379: 1
475072400: 1
378706832: 1
495470244: 1
291349885: 1
54310764: 1
316282903: 1
433805220: 1
261348271: 1
309216788: 1
244596251: 1
225445899: 1
315477089: 1
249074601: 1
353782028: 1
425137311: 1
90076961: 1
476359652: 1
166146452: 1
446508903: 1
361712484: 1
192258929: 1
77297306: 1
107096310: 1
2186129: 1
17500259: 1
48928837: 1
188166558: 1
408707022: 1
316003479: 1
424292433: 1
63710451: 1
115851983: 1
425597131: 1
156854114: 1
347732795: 1
353652788: 1
168672848: 1
98166998: 1
496148859: 1
292997793: 1
132440100: 1
340069127: 1
16078231: 1
74052818: 1
64562205: 1
15393973: 1
257125833: 1
468432370: 1
241105302: 1
252053106: 1
116689706: 1
172418593: 1
500596723: 1
187509387: 1
273811134: 1
419551474: 1
50032197: 1
71951900: 1
252189460: 1
439483461: 1
270760915: 1
342051503: 1
91452844: 1
408919740: 1
287304646: 1
499152734: 1
19786134: 1
23523669: 1
83927279: 1
446030695: 1
163512172: 1
217432312: 1
89023851: 1
82592801: 1
533855910: 1
392512581: 1
242189929: 1
287199666: 1
323407795: 1
408957920: 1
179909217: 1
243638005: 1
231990346: 1
228402118: 1
491730533: 1
353787559: 1
352790695: 1
106207770: 1
130331961: 1
107694512: 1
455169331: 1
289778353: 1
330521380: 1
103061784: 1
188858699: 1
526374263: 1
239420970: 1
464915008: 1
248266436: 1
260787258: 1
39258321: 1
76640074: 1
279438798: 1
171289719: 1
270004781: 1
504559659: 1
61265360: 1
417359183: 1
368171605: 1
42444855: 1
251719622: 1
179759251: 1
186821904: 1
437263072: 1
503794874: 1
535297875: 1
47651123: 1
307199209: 1
214783195: 1
498915993: 1
418960857: 1
196709246: 1
10016719: 1
190801858: 1
323910435: 1
30336266: 1
196008920: 1
173965759: 1
329154824: 1
391496646: 1
512402645: 1
234674040: 1
43885569: 1
398795612: 1
426178266: 1
293887158: 1
410843041: 1
380116702: 1
313947985: 1
83326944: 1
84015284: 1
453613828: 1
98004313: 1
519284683: 1
109069982: 1
124410095: 1
315506799: 1
481565987: 1
249758383: 1
436763202: 1
145274775: 1
411382769: 1
1769045: 1
449246083: 1
284202223: 1
60119751: 1
269993734: 1
305505189: 1
311862435: 1
50652778: 1
297813589: 1
324700641: 1
91476520: 1
486329938: 1
271441956: 1
523725524: 1
466525882: 1
40131629: 1
12824807: 1
352205268: 1
513159555: 1
8640157: 1
363669076: 1
222948077: 1
263064664: 1
184985080: 1
146120266: 1
124386042: 1
329393644: 1
326756636: 1
221198864: 1
493026528: 1
71482950: 1
107017842: 1
260406912: 1
529255606: 1
367490919: 1
487970236: 1
29210690: 1
188305639: 1
192098996: 1
103374797: 1
329864708: 1
282685603: 1
29621434: 1
414668727: 1
527973467: 1
398720297: 1
239878661: 1
390879282: 1
242560356: 1
286465999: 1
125830672: 1
376844912: 1
155885114: 1
514945868: 1
519278956: 1
273180103: 1
492376177: 1
219729143: 1
178673221: 1
84860107: 1
438441715: 1
257226169: 1
152044267: 1
194951823: 1
163123988: 1
60259893: 1
458484333: 1
204743895: 1
135604210: 1
199281792: 1
410074550: 1
310709608: 1
103925720: 1
80407629: 1
155885661: 1
196851339: 1
121839841: 1
393745946: 1
164760856: 1
314186692: 1
299308977: 1
430415525: 1
389878912: 1
384551771: 1
484403976: 1
471961585: 1
106949830: 1
30488182: 1
257193018: 1
6746703: 1
494545764: 1
529050572: 1
187634074: 1
306302547: 1
341141011: 1
86598796: 1
64165843: 1
473856182: 1
155192555: 1
377092713: 1
17327851: 1
531185264: 1
149836933: 1
56472186: 1
156103278: 1
352189886: 1
525580308: 1
490428768: 1
457557181: 1
151068493: 1
148666275: 1
507255756: 1
368456303: 1
16387018: 1
123573370: 1
506479340: 1
49389445: 1
390641982: 1
366020733: 1
204147568: 1
467642115: 1
348436439: 1
279388174: 1
234251400: 1
241893732: 1
299598552: 1
18988778: 1
166045104: 1
86487683: 1
188323482: 1
429091150: 1
7547597: 1
82253362: 1
290574025: 1
86617538: 1
162816119: 1
295730325: 1
451426428: 1
476165871: 1
51894966: 1
39031455: 1
197958922: 1
99715250: 1
490794961: 1
352570164: 1
312802992: 1
115437606: 1
217879250: 1
477312284: 1
481485649: 1
133891840: 1
300330514: 1
529797695: 1
529516119: 1
378545302: 1
524812069: 1
478584608: 1
233860485: 1
431390545: 1
322492208: 1
247863991: 1
330829024: 1
283992824: 1
380379655: 1
417531080: 1
330197013: 1
455332774: 1
202410085: 1
493229708: 1
39883770: 1
207551429: 1
304593990: 1
44007224: 1
283625425: 1
514748164: 1
216762269: 1
8387535: 1
354879936: 1
149991087: 1
185216898: 1
337512527: 1
311356955: 1
317825407: 1
213899146: 1
193473226: 1
246872368: 1
517136028: 1
520535551: 1
482156468: 1
351789439: 1
115417818: 1
436138691: 1
311652364: 1
209801621: 1
103031851: 1
23273321: 1
44602302: 1
50895440: 1
23544254: 1
84642402: 1
518789303: 1
342579246: 1
446571893: 1
478808800: 1
445840016: 1
361830469: 1
482738466: 1
344418015: 1
453435751: 1
14323501: 1
51108150: 1
426759143: 1
436605908: 1
278220974: 1
40841247: 1
222693898: 1
490321022: 1
370589984: 1
266156320: 1
276845570: 1
116620100: 1
5029531: 1
201801323: 1
245540897: 1
109476222: 1
472004662: 1
181444738: 1
515961506: 1
277929826: 1
279002404: 1
183380383: 1
265768683: 1
359968203: 1
261780339: 1
497072749: 1
447204355: 1
227768224: 1
517700138: 1
388640617: 1
173387305: 1
108394065: 1
475012382: 1
474888698: 1
350103421: 1
17446921: 1
529360140: 1
226759542: 1
253575555: 1
503569998: 1
37750668: 1
252214908: 1
236915772: 1
55957232: 1
180041071: 1
362388033: 1
259781947: 1
261909090: 1
236855035: 1
15242662: 1
482750305: 1
316813651: 1
193135213: 1
122776654: 1
381053119: 1
62137824: 1
4033985: 1
285243405: 1
169212634: 1
115085105: 1
240382226: 1
342316302: 1
290752778: 1
393619246: 1
454695125: 1
172869764: 1
341325098: 1
131296596: 1
503900475: 1
22348220: 1
352774961: 1
113810059: 1
344977065: 1
373557522: 1
130872200: 1
334005572: 1
21167674: 1
299553636: 1
78035467: 1
266885694: 1
26584815: 1
44296784: 1
531981560: 1
439506236: 1
126257303: 1
218667927: 1
63221834: 1
210434164: 1
67627082: 1
28756350: 1
458040348: 1
235208155: 1
247038146: 1
467823809: 1
525150884: 1
451261340: 1
123498043: 1
222963577: 1
181419000: 1
464313323: 1
354706878: 1
412288301: 1
459945618: 1
244544587: 1
307141259: 1
422814830: 1
491012603: 1
123946539: 1
20821986: 1
255970695: 1
161161793: 1
208907317: 1
255974444: 1
40280372: 1
116574783: 1
104486592: 1
432525859: 1
392399319: 1
115623786: 1
383879792: 1
529939454: 1
39915520: 1
136876639: 1
349312026: 1
241075937: 1
399949703: 1
165404866: 1
221557289: 1
224886669: 1
403492352: 1
113376467: 1
291294748: 1
431819075: 1
241932012: 1
462817846: 1
135288497: 1
123625247: 1
268368135: 1
220128853: 1
474064118: 1
486046428: 1
96282530: 1
77947543: 1
536820286: 1
179514428: 1
170403174: 1
518098473: 1
147713815: 1
2936570: 1
423412756: 1
112736232: 1
84893730: 1
189818704: 1
139165719: 1
155085995: 1
439503886: 1
300607009: 1
197552880: 1
173982124: 1
373460482: 1
404718142: 1
461989029: 1
145420249: 1
346496872: 1
106028271: 1
435593639: 1
440604625: 1
60037840: 1
237216673: 1
5491005: 1
381837487: 1
148633773: 1
408128034: 1
424097427: 1
109772259: 1
318421417: 1
83015921: 1
32956531: 1
374301334: 1
423624817: 1
198280799: 1
191576042: 1
442092925: 1
50894187: 1
265342993: 1
416781251: 1
388023111: 1
217785168: 1
423493803: 1
280931304: 1
533552366: 1
349922437: 1
15617034: 1
241423906: 1
124509606: 1
239571918: 1
506831646: 1
428694609: 1
428854049: 1
123044700: 1
263467398: 1
67480500: 1
18772554: 1
294736741: 1
104161040: 1
420668881: 1
199723146: 1
76693620: 1
365966599: 1
321799744: 1
179394136: 1
514129: 1
99766576: 1
428452417: 1
368597160: 1
495693362: 1
336112515: 1
60170944: 1
298019123: 1
55070411: 1
214766601: 1
353615134: 1
478608394: 1
229262058: 1
422914009: 1
13607053: 1
204473187: 1
69401991: 1
28274420: 1
506253599: 1
113542645: 1
525171594: 1
489623170: 1
170709122: 1
379302594: 1
435652394: 1
177783823: 1
433290416: 1
230795983: 1
301693565: 1
468899628: 1
247788543: 1
370047831: 1
386833436: 1
273280793: 1
154828387: 1
408346462: 1
265520525: 1
463117632: 1
384228304: 1
67550796: 1
327244485: 1
501788497: 1
288699396: 1
75951826: 1
526740254: 1
334723615: 1
518163375: 1
341658653: 1
106801980: 1
181800244: 1
105799921: 1
73316274: 1
451231520: 1
517380230: 1
273830959: 1
324428553: 1
315483310: 1
342819735: 1
388016833: 1
529365722: 1
87586354: 1
9236056: 1
418975281: 1
171865902: 1
364475737: 1
194431711: 1
334372807: 1
103532157: 1
439742056: 1
215253183: 1
91487934: 1
125583559: 1
233385103: 1
435808824: 1
181748942: 1
14871447: 1
305660586: 1
334413288: 1
470820872: 1
199960064: 1
339622369: 1
178270312: 1
409920404: 1
339701775: 1
199676688: 1
187412082: 1
108578651: 1
82215629: 1
439225909: 1
374132676: 1
400176166: 1
302632915: 1
431315706: 1
469913552: 1
138983587: 1
203787957: 1
441807988: 1
148817684: 1
138633035: 1
288581957: 1
394742176: 1
286841396: 1
87307017: 1
292894295: 1
267135906: 1
309214256: 1
272748016: 1
113112871: 1
124072250: 1
32685707: 1
395165610: 1
269157643: 1
413460843: 1
246544345: 1
412969461: 1
431399725: 1
169097979: 1
276968939: 1
88823368: 1
101618344: 1
215089833: 1
162486310: 1
290639883: 1
180653910: 1
209311659: 1
248685620: 1
345642966: 1
184382295: 1
161516595: 1
329241888: 1
456876861: 1
201322636: 1
88812446: 1
424043710: 1
428982366: 1
202557300: 1
386624441: 1
445141733: 1
384999504: 1
162855504: 1
117910742: 1
476969843: 1
381760888: 1
76802828: 1
200337077: 1
150220814: 1
242111525: 1
95364597: 1
50743754: 1
444908888: 1
394495214: 1
224690229: 1
432049099: 1
2092111: 1
438552663: 1
137196866: 1
33961455: 1
77540464: 1
197674065: 1
290462775: 1
487331257: 1
74537942: 1
268299898: 1
183922777: 1
107741627: 1
188469912: 1
119553157: 1
11090151: 1
114785514: 1
509593601: 1
425557200: 1
33822298: 1
114609674: 1
48881943: 1
25261532: 1
71741177: 1
180650866: 1
443770416: 1
431659764: 1
505577783: 1
476445720: 1
293823894: 1
96320451: 1
46755524: 1
284689364: 1
235464513: 1
341522866: 1
508745794: 1
207595917: 1
358117099: 1
341770356: 1
209115691: 1
126121520: 1
69957536: 1
227179998: 1
353006275: 1
237873550: 1
268544567: 1
420093231: 1
227639373: 1
469670111: 1
400307158: 1
642193: 1
254428923: 1
53340304: 1
514688573: 1
459978081: 1
7828006: 1
26629288: 1
38590347: 1
272324707: 1
501205715: 1
117876931: 1
152965524: 1
110540968: 1
126337165: 1
516051414: 1
30832391: 1
158627248: 1
463690846: 1
345764527: 1
158215870: 1
297298596: 1
280059135: 1
452973196: 1
47011004: 1
247107278: 1
486800872: 1
441676431: 1
461924583: 1
343674832: 1
53852954: 1
460806490: 1
337667162: 1
531992124: 1
113226198: 1
50068221: 1
382750999: 1
328592990: 1
475161522: 1
319994728: 1
357587042: 1
520166406: 1
286160549: 1
4480648: 1
215473164: 1
134651788: 1
303073361: 1
515620433: 1
515670834: 1
450783158: 1
16977936: 1
392580648: 1
238687342: 1
215377306: 1
381905607: 1
301528658: 1
493267452: 1
438961277: 1
359183087: 1
283565169: 1
85253526: 1
74747641: 1
21705151: 1
466858889: 1
332022896: 1
191833618: 1
256217104: 1
5180125: 1
165943573: 1
510889323: 1
74217955: 1
184461595: 1
373117184: 1
266192107: 1
53421434: 1
143460049: 1
316767423: 1
177356111: 1
313135625: 1
438373203: 1
449957294: 1
451672864: 1
60731339: 1
449085140: 1
209702745: 1
164291632: 1
282924894: 1
36646085: 1
250922593: 1
451050114: 1
51513903: 1
536092372: 1
154146139: 1
32329093: 1
273990373: 1
264157089: 1
158256741: 1
354105838: 1
209859329: 1
193932567: 1
15061451: 1
414339858: 1
445105509: 1
251589689: 1
100986856: 1
261857258: 1
242513754: 1
269797551: 1
400661251: 1
196566054: 1
395386014: 1
136249680: 1
83335152: 1
255562918: 1
430489112: 1
456369147: 1
174344861: 1
406763312: 1
135006534: 1
129710286: 1
41342576: 1
218771246: 1
143671045: 1
177336997: 1
442573215: 1
148105808: 1
13481460: 1
508934198: 1
304085615: 1
294199006: 1
193180099: 1
282392526: 1
385122073: 1
244215445: 1
228814364: 1
420015355: 1
258734610: 1
480629125: 1
465001742: 1
427689716: 1
237822089: 1
161342203: 1
387041362: 1
522517178: 1
380722729: 1
479200414: 1
274491174: 1
493097975: 1
173811480: 1
198863798: 1
518261167: 1
112677801: 1
270822442: 1
251270380: 1
357222480: 1
345634984: 1
358201250: 1
100672147: 1
230370157: 1
343811308: 1
430452223: 1
360850730: 1
273390807: 1
486277752: 1
30820555: 1
303670532: 1
403886823: 1
315279049: 1
451690230: 1
355446653: 1
204914154: 1
530155219: 1
466086212: 1
7848841: 1
97892821: 1
222526782: 1
175305404: 1
85872582: 1
225490920: 1
175883766: 1
73308025: 1
523551835: 1
496886091: 1
216478115: 1
254414898: 1
15632809: 1
429701506: 1
219620116: 1
240638193: 1
342727799: 1
509235982: 1
235702418: 1
419058879: 1
187864840: 1
166237164: 1
285520345: 1
193065148: 1
Out[ ]: